<?php
/**
 * 账单
 */
namespace App\Validation;

use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Numericality;
use Phalcon\Validation\Validator\InclusionIn;

class BillValidation extends BaseValidation
{
	public function initialize()
	{
		$this->add(
			"pay",
			new InclusionIn(
				  [
					  "field" => "pay",
					  "domain" => [0,1,2],//0获取会员收益，1获取会员打赏账单，2获取会员支付数据账单
					  "message" => ":field is not included in 0 or 1 or 2",
				  ]
			)
		);

		$this->add(
			"p",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
				  ]
			)
		);
		
		$this->add(
			"page_num",
			new Numericality(
				  [
					  "message" => ":field is not numeric",
				  ]
			)
		);
	}

	//验证之前
	public function beforeValidation($data, $entity, $messages)
    {
    	parent::beforeValidation($data, $entity, $messages);

    	$data->pay = property_exists($data,'pay') ? $data->pay : 0;

        return true;
    }
}